<?php
namespace app\index\model;

//use app\index\controller\user;
//use Couchbase\UserSettings;
use think\model;
class goods extends Model
{
    public function searchIsshowAttr($q,$v,$d)
    {
        $q->where('is_show','=',"$v");
    }

    public function searchIshotAttr($q,$v,$d)
    {
        $q->where('is_hot','=',"$v");
    }

    public function searchIsdownAttr($q,$v,$d)
    {
        $q->where('is_down','in',"$v");
    }

    public function searchCidAttr($q,$v,$d)
    {
        $q->where('cid','=',"$v");
    }

    public function searchKeywordsAttr($q,$v,$d)
    {
        $q->where('a.name','like',"%{$v}%");
    }

    public function searchTimeAttr($q,$v,$d)
    {
        $q->where('addtime','>= time',"$v");
    }

    public function searchTime1Attr($q,$v,$d)
    {
        $q->where('addtime','<= time',"$v");
    }

    public function searchPriceAttr($q,$v,$d)
    {
        $q->where('price','>=',"$v");
    }

    public function searchPrice1Attr($q,$v,$d)
    {
        $q->where('price','<=',"$v");
    }
    public static function goodList($where)
    {
        $list=goods::alias('a')
            ->withSearch(array_keys($where),$where)
            ->join(' ecm_category b','a.cid=b.id')
            ->field('a.id,a.name,a.price,a.photo_x,a.content,a.addtime,a.sort,a.is_show,a.is_down,a.is_hot,b.name as bname')
            ->paginate(
            [
                'list_rows'=>2,
                'query'=>$where

            ]
        );
        return $list;
    }
}